
(deftemplate propozitie
    (slot persoana)
    (slot actiune)
    (slot p_locatie)
    (slot locatie)
    (slot ora_start)
    (slot min_start)
    (slot sec_start)
    (slot ora_end)
    (slot min_end)
    (slot sec_end)
)

(assert (propozitie (persoana "Vlad") (actiune "utilizare wc") (locatie "baie2") (ora_start 22) (min_start 32) (sec_start 0) (ora_end 22) (min_end 33) (sec_end 0) ))
(assert (propozitie (persoana "Ana") (actiune "utilizare wc") (locatie "baie1") (ora_start 22) (min_start 2) (sec_start 0) (ora_end 22) (min_end 3) (sec_end 0) ))
(assert (propozitie (persoana "Alina") (actiune "utilizare wc") (locatie "baie1") (ora_start 20) (min_start 1) (sec_start 0) (ora_end 20) (min_end 2) (sec_end 0) ))
(assert (propozitie (persoana "Alina") (actiune "utilizare dus") (locatie "baie1") (ora_start 18) (min_start 36) (sec_start 0) (ora_end 20) (min_end 0) (sec_end 0) ))
(assert (propozitie (persoana "Ana") (actiune "utilizare frigider") (locatie "bucatarie") (ora_start 18) (min_start 32) (sec_start 0) (ora_end 18) (min_end 35) (sec_end 0) ))
(assert (propozitie (persoana "Ion") (actiune "utilizare tv") (locatie "living") (ora_start 18) (min_start 30) (sec_start 0) (ora_end 23) (min_end 30) (sec_end 0) ))
(assert (propozitie (persoana "Alina") (actiune "utilizare tv") (locatie "living") (ora_start 16) (min_start 45) (sec_start 0) (ora_end 17) (min_end 30) (sec_end 0) ))
(assert (propozitie (persoana "Alina") (actiune "utilizare wc") (locatie "baie2") (ora_start 16) (min_start 42) (sec_start 0) (ora_end 16) (min_end 43) (sec_end 0) ))
(assert (propozitie (persoana "Vlad") (actiune "utilizare calculator") (locatie "living") (ora_start 16) (min_start 35) (sec_start 0) (ora_end 17) (min_end 30) (sec_end 0) ))
(assert (propozitie (persoana "Vlad") (actiune "utilizare dus") (locatie "baie1") (ora_start 16) (min_start 33) (sec_start 0) (ora_end 16) (min_end 33) (sec_end 30) ))
(assert (propozitie (persoana "Vlad") (actiune "utilizare wc") (locatie "baie1") (ora_start 16) (min_start 32) (sec_start 0) (ora_end 16) (min_end 33) (sec_end 0) ))
(assert (propozitie (persoana "Ana") (actiune "gateste") (locatie "bucatarie") (ora_start 16) (min_start 15) (sec_start 0) (ora_end 17) (min_end 30) (sec_end 0) ))
(assert (propozitie (persoana "Ana") (actiune "utilizare frigider") (locatie "bucatarie") (ora_start 16) (min_start 1) (sec_start 0) (ora_end 16) (min_end 15) (sec_end 0) ))
(assert (propozitie (persoana "Ana") (actiune "utilizare masina de spalat") (locatie "baie2") (ora_start 14) (min_start 32) (sec_start 0) (ora_end 16) (min_end 0) (sec_end 0) ))
(assert (propozitie (persoana "Ana") (actiune "utilizare tv") (locatie "living") (ora_start 7) (min_start 55) (sec_start 0) (ora_end 10) (min_end 0) (sec_end 0) ))
(assert (propozitie (persoana "Ana") (actiune "utilizare wc") (locatie "baie2") (ora_start 7) (min_start 52) (sec_start 0) (ora_end 7) (min_end 53) (sec_end 0) ))
(assert (propozitie (persoana "Vlad") (actiune "utilizare wc") (locatie "baie2") (ora_start 7) (min_start 44) (sec_start 0) (ora_end 7) (min_end 46) (sec_end 0) ))
(assert (propozitie (persoana "Alina") (actiune "gateste") (locatie "bucatarie") (ora_start 7) (min_start 30) (sec_start 0) (ora_end 7) (min_end 48) (sec_end 0) ))
(assert (propozitie (persoana "Vlad") (actiune "gateste") (locatie "bucatarie") (ora_start 7) (min_start 30) (sec_start 0) (ora_end 7) (min_end 42) (sec_end 0) ))
(assert (propozitie (persoana "Ion") (actiune "gateste") (locatie "bucatarie") (ora_start 7) (min_start 30) (sec_start 0) (ora_end 7) (min_end 45) (sec_end 0) ))
(assert (propozitie (persoana "Ana") (actiune "gateste") (locatie "bucatarie") (ora_start 7) (min_start 30) (sec_start 0) (ora_end 7) (min_end 50) (sec_end 0) ))
(assert (propozitie (persoana "Alina") (actiune "utilizare wc") (locatie "baie2") (ora_start 7) (min_start 25) (sec_start 0) (ora_end 7) (min_end 26) (sec_end 0) ))
(assert (propozitie (persoana "Alina") (actiune "utilizare dus") (locatie "baie2") (ora_start 7) (min_start 21) (sec_start 0) (ora_end 7) (min_end 25) (sec_end 0) ))
(assert (propozitie (persoana "Ion") (actiune "utilizare wc") (locatie "baie1") (ora_start 7) (min_start 11) (sec_start 0) (ora_end 7) (min_end 20) (sec_end 0) ))
(assert (propozitie (persoana "Ana") (actiune "gateste") (locatie "bucatarie") (ora_start 7) (min_start 10) (sec_start 0) (ora_end 7) (min_end 30) (sec_end 0) ))
(assert (propozitie (persoana "Ana") (actiune "utilizare frigider") (locatie "bucatarie") (ora_start 7) (min_start 6) (sec_start 15) (ora_end 7) (min_end 10) (sec_end 0) ))
(assert (propozitie (persoana "Ana") (actiune "utilizare  dus") (locatie "baie1") (ora_start 7) (min_start 1) (sec_start 30) (ora_end 7) (min_end 4) (sec_end 0)  ))
(assert (propozitie (persoana "Alina") (actiune "utilizare  frigider") (locatie "bucatarie") (ora_start 1) (min_start 32) (sec_start 15) (ora_end 1) (min_end 33) (sec_end 0) ))
(assert (propozitie (persoana "Ion") (actiune "utilizare dus") (locatie "baie1") (ora_start 24) (min_start 2) (sec_start 0) (ora_end 24) (min_end 10) (sec_end 0) ))






(deftemplate aragaz (slot camera) (slot stare))   
(deftemplate frigider (slot camera) (slot stare)) 
(deftemplate dus (slot camera) (slot stare))	
(deftemplate masina_de_spalat (slot camera)(slot stare))
(deftemplate wc (slot camera) (slot stare))			
(deftemplate calculator (slot camera) (slot stare))	
(deftemplate tv (slot camera) (slot stare))	

(assert (calculator (camera "living") (stare 0)))
(assert (tv (camera "living") (stare 0)))
(assert (dus (camera "baie1") (stare 0)))
(assert (dus (camera "baie2") (stare 0)))
(assert (wc (camera "baie1") (stare 0)))
(assert (wc (camera "baie2") (stare 0)))
(assert (masina_de_spalat(camera "baie1") (stare 0)))
(assert (aragaz (camera "bucatarie") (stare 0)))
(assert (frigider (camera "bucatarie") (stare 0)))






(open "texxt.txt" mydata "w")
(defrule tv_on
	
    ?p <- (propozitie (actiune "utilizare tv") (locatie ?l)  (ora_start ?hs) (min_start ?ms) (sec_start ?ss) (ora_end ?he) (min_end ?me) (sec_end ?se))
    ?t <- (tv(stare 0) (camera ?c))  
       =>
     (retract ?t)
     (assert (tv (stare 1) (camera ?c))) 
    
	   (printout mydata " Televizorul porneste la ora "  ?hs ":" ?ms ":" ?ss crlf) 
     
     
    )

( defrule tv_off 
 
    ?p <- (propozitie (actiune "utilizare tv") (locatie ?l)  (ora_start ?hs) (min_start ?ms) (sec_start ?ss) (ora_end ?he) (min_end ?me) (sec_end ?se))
    ?t <- (tv (stare 1) (camera ?c))  
   =>
     (retract ?t)
    (assert (tv (stare 0) (camera ?c))) 
      (printout mydata "Televizorul se opreste la ora "  ?he ":" ?me ":" ?se crlf) 
      
     (retract ?p) 
    )

(defrule calculator_on
    ?p <- (propozitie (actiune "utilizare calculator") (locatie ?l)  (ora_start ?hs) (min_start ?ms) (sec_start ?ss) (ora_end ?he) (min_end ?me) (sec_end ?se))
    ?cc <- (calculator (stare 0) (camera ?c))  
     =>
     (retract ?cc)
     (assert (calculator (stare 1) (camera ?c))) 
	 
    (printout mydata "Calculatorul porneste la ora "  ?hs ":" ?ms ":" ?ss crlf) 
     
    )

(defrule calculator_off
    ?p <- (propozitie (actiune "utilizare calculator") (locatie ?l)  (ora_start ?hs) (min_start ?ms) (sec_start ?ss) (ora_end ?he) (min_end ?me) (sec_end ?se))
    ?cc <- (calculator (stare 1) (camera ?c))  
     =>
     (retract ?cc)
    (assert (calculator (stare 0) (camera ?c))) 
      (printout mydata "Calculatorul se opreste la ora "  ?he"" ?me ":" ?se crlf) 
    
     (retract ?p)     
    )

(defrule frigider_on
    ?p <- (propozitie (actiune "utilizare frigider") (locatie ?l)  (ora_start ?hs) (min_start ?ms) (sec_start ?ss) (ora_end ?he) (min_end ?me) (sec_end ?se))
    ?f <- (frigider (stare 0) (camera ?c))  
     =>
     (retract ?f)
     (assert (frigider (stare 1) (camera ?c))) 
    (printout mydata "Frigiderul se deschide la ora "  ?hs ":" ?ms ":" ?ss crlf) 
    
    )

(defrule frigider_off
    ?p <- (propozitie (actiune "utilizare frigider") (locatie ?l)  (ora_start ?hs) (min_start ?ms) (sec_start ?ss) (ora_end ?he) (min_end ?me) (sec_end ?se))
    ?f <- (frigider (stare 1) (camera ?c))  
     =>
     (retract ?f)
    (assert (frigider (stare 0) (camera ?c))) 
      (printout mydata "Frigiderul se inchide la ora "  ?he ":" ?me ":" ?se crlf) 
    
     (retract ?p)     
    )

(defrule aragaz_on
    ?p <- (propozitie (actiune "gateste") (locatie ?l)  (ora_start ?hs) (min_start ?ms) (sec_start ?ss) (ora_end ?he) (min_end ?me) (sec_end ?se))
    ?a <- (aragaz (stare 0) (camera ?c))  
     =>
     (retract ?a)
     (assert (aragaz (stare 1) (camera ?c))) 
	 
    (printout mydata "Aragazul se aprinde la ora "  ?hs ":" ?ms ":" ?ss crlf) 
     
    )

(defrule aragaz_off
    ?p <- (propozitie (actiune "gateste") (locatie ?l)  (ora_start ?hs) (min_start ?ms) (sec_start ?ss) (ora_end ?he) (min_end ?me) (sec_end ?se))
    ?a <- (aragaz (stare 1) (camera ?c))  
     =>
     (retract ?a)
    (assert (aragaz (stare 0) (camera ?c))) 
      (printout mydata "Aragazul se stinge la ora "  ?he ":" ?me ":" ?se crlf) 
    
     (retract ?p)     
    )

(defrule masina_on
    ?p <- (propozitie (actiune "utilizare masina de spalat") (locatie ?l)  (ora_start ?hs) (min_start ?ms) (sec_start ?ss) (ora_end ?he) (min_end ?me) (sec_end ?se))
    ?m <- (masina_de_spalat(stare 0) (camera ?c))  
     =>
     (retract ?m)
     (assert (masina_de_spalat (stare 1) (camera ?c))) 
	 
    (printout mydata "Masina de spalat porneste in "  ?c " la ora "  ?hs ":" ?ms ":" ?ss  crlf) 
     
    )

        
( defrule masina_off
    ?p <- (propozitie (actiune "utilizare masina de spalat") (locatie ?l)  (ora_start ?hs) (min_start ?ms) (sec_start ?ss) (ora_end ?he) (min_end ?me) (sec_end ?se))
    ?m <- (masina_de_spalat (stare 1) (camera ?c))  
     =>
     (retract ?m)
    (assert (masina_de_spalat (stare 0) (camera ?c))) 
      (printout mydata "Masina de spalat se opreste in " ?c " la ora "  ?he ":"  ?me ":" ?se  crlf) 
    
     (retract ?p)     
    )

(defrule dus_on
    ?p <- (propozitie (actiune "utilizare dus") (locatie ?l)  (ora_start ?hs) (min_start ?ms) (sec_start ?ss) (ora_end ?he) (min_end ?me) (sec_end ?se))
    ?d <- (dus (stare 0) (camera ?c))  
     =>
     (retract ?d)
     (assert (dus (stare 1) (camera ?c))) 
	 
     (printout mydata "Dusul porneste in " ?c " la ora "  ?he ":" ?me ":" ?se   crlf) 
     
    )

( defrule dus_off
    ?p <- (propozitie (actiune "utilizare dus") (locatie ?l)  (ora_start ?hs) (min_start ?ms) (sec_start ?ss) (ora_end ?he) (min_end ?me) (sec_end ?se))
    ?d <- (dus (stare 1) (camera ?c))  
     =>
     (retract ?d)
     (assert (dus (stare 0) (camera ?c))) 
     (printout mydata "Dusul se opreste in " ?c " la ora "  ?he ":" ?me ":" ?se  crlf) 
    
     (retract ?p)     
    )

(defrule wc_on
    ?p <- (propozitie (actiune "utilizare wc") (locatie ?l)  (ora_start ?hs) (min_start ?ms) (sec_start ?ss) (ora_end ?he) (min_end ?me) (sec_end ?se))
    ?w <- (wc (stare 0) (camera ?c))
  
     =>
     (retract ?w)
     (assert (wc (stare 1) (camera ?c))) 
	 
     (printout mydata "Wc porneste in " ?c " la ora "  ?hs ":" ?ms ":" ?ss  crlf ) 
     
    )

( defrule wc_off
    ?p <- (propozitie (actiune "utilizare wc") (locatie ?c)  (ora_start ?hs) (min_start ?ms) (sec_start ?ss) (ora_end ?he) (min_end ?me) (sec_end ?se))
    ?w <- (wc (stare 1) (camera ?c))  
     =>
     (retract ?w)
     (assert (wc (stare 0) (camera ?c)))
     
     (printout mydata "Wc se opreste in " ?c " la  ora "  ?he ":" ?me ":" ?se  crlf) 
    
     (retract ?p)     
    )


(run)

